@echo off
setlocal

if "%JAVAEE_HOME%"=="" set JAVAEE_HOME="C:/Program Files/glassfish"
set ASADMIN=%JAVAEE_HOME%/bin/asadmin.bat

if not exist "%ASADMIN%" goto config

if "%1"=="start" goto start
if "%1"=="stop" goto stop
goto usage

:start
echo .
echo Starting GlassFish...
call "%ASADMIN%" start-domain
echo .
echo Starting Derby
call "%ASADMIN%" start-database
goto end

:stop
echo .
echo Stopping Derby...
call "%ASADMIN%" stop-database
echo .
echo Stopping GlassFish...
call "%ASADMIN%" stop-domain
goto end

:config
echo %ASADMIN% does not exist.
echo Set JAVAEE_HOME correctly.

:usage
echo "Usage: asadmin start|stop"
goto end

:end
endlocal
echo .
echo Done, press Ctl-C if script seems to hang.